package day9;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author oldliu
 * @since 1.0
 */
public class MyServer {
    public static void main(String[] args) {
        try {
            ServerSocket st=new ServerSocket(8888);
            System.out.println("服务器启动，监听在8888端口");
            while (true){
                Socket s = st.accept();
                System.out.println("ip:"+s.getInetAddress());
                System.out.println("远程端口："+s.getPort());
                System.out.println(s.getLocalPort()+"本地");
                System.out.println("socket连接建立了。。。"+s);
                InputStream in = s.getInputStream();
                OutputStream out = s.getOutputStream();
                //>>>
                int ch =0;
                while ((ch=in.read())!=-1){
                    System.out.print((char)ch);
                }
                //in.available()不可用，0

            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
